#include "gui/VisualComponents/VisualCompositeComponent.h"

VisualCompositeComponent::VisualCompositeComponent() {
	m_selected = false;
}

VisualCompositeComponent::VisualCompositeComponent(const VisualCompositeComponent &other) {
	m_selected = false;
}


VisualCompositeComponent::~VisualCompositeComponent() {
	for (std::vector<VisualComponent*>::iterator it = m_children.begin(); it != m_children.end(); ++it)
		delete (*it);
}

void VisualCompositeComponent::addChild(VisualComponent* child) {
	m_children.push_back(child);
}

void VisualCompositeComponent::addView(VisualCompositeComponent* view) {
	m_views.push_back(view);
}

void VisualCompositeComponent::removeChild(VisualComponent* child) {
	for (std::vector<VisualComponent*>::iterator it = m_children.begin(); it != m_children.end(); ++it)
		if ((*it) == child) {
			m_children.erase(it);
			return;
		}
}

VisualComponent* VisualCompositeComponent::getTouchedSubVisualComponent(int x, int y) {
	for (std::vector<VisualComponent*>::iterator it = m_children.begin(); it != m_children.end(); ++it)
		if ((*it)->getInfluenceArea().touch(x, y))
			return (*it);
	return NULL;
}

void VisualCompositeComponent::draw(Cairo::RefPtr<Cairo::Context> ptrContext){
	for (std::vector<VisualComponent*>::iterator it = m_children.begin(); it != m_children.end(); ++it)
		(*it)->draw(ptrContext);
}

/*
void VisualCompositeComponent::serializedAttributes(XmlWriter & xml, Diagram * diagram, Component * component){

	xmlNode* nodoActual;
	Utils utils;

	m_component->update();

	std::string tipo;

	for (std::vector<Attribute*>::iterator it = component->getAtrributes()->begin(); it != component->getAtrributes()->end(); ++it)
	{
		tipo = typeid(**it).name();
		if (tipo.substr(1,8) != "Relation"){
			nodoActual = xml.addCurrentNodeChild("atributo", "");
			xml.addProperty(nodoActual, TARGET_ID, utils.convertToString(diagram->getId(*it)).c_str());
			xml.addProperty(nodoActual, TARGET_NAME, (*it)->getName().c_str());
		}
	}
}
*/
